﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using Microsoft.Practices.Prism.Events;
using QLab.Events;

namespace QLab.Services
{
	[Export(typeof(ICodeExecutionService))]
	[PartCreationPolicy(CreationPolicy.Shared)]
	public class CodeExecutionService : ICodeExecutionService
	{
		private ICommandHistoryService _commandHistoryService;
		private IEventAggregator _eventAggregator;

		[ImportingConstructor]
		public CodeExecutionService(IEventAggregator EventAggregator, ICommandHistoryService CommandHistoryService)
		{
			_eventAggregator = EventAggregator;
			_commandHistoryService = CommandHistoryService;
		}

		#region Methods

		public void ExecuteCommand(string CommandText)
		{
			_eventAggregator.GetEvent<BeforeCommandExecuting>().Publish(CommandText);
			_commandHistoryService.LogCommand(CommandText);

			//TODO: Call engine

			_eventAggregator.GetEvent<CommandExecuted>().Publish(CommandText);
		}

		#endregion
	}
}
